package com.loveprogrammer.eternity.skill.support.skills;

import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.common.Tuple;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0.0
 * @description: 治疗
 * @author: eric
 * @date: 2022-08-11 16:49
 **/
public class SkillTreatment extends AbstractSkill {

    public SkillTreatment(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    public boolean check(Character character) {
        return true;
    }

    @Override
    public int opportunityPassive() {
        // 0为 主动技能
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每两级升一级
        if(characterLevel % 2 == 0){
            return true;
        }
        return false;
    }

    /***
     * 发动技能
     **/
    @Override
    public Tuple<String, List<Character>> skillLaunch(Character character,
                                                      List<? extends Character> attack,
                                                      List<? extends Character> defences) {

        int power = getHarm(character);
        // 如果己方有生命值不满的情况，施加圣言术恢复生命力
        int maxHp = 0;
        Character character1 = null;
        for (Character cha : attack) {
            int currentHp = cha.getCurrentHp();
            int hpMax = cha.getHpMax();
            if(currentHp < hpMax * 0.9){
                int reduce = hpMax - currentHp;
                if(reduce > maxHp){
                    maxHp = reduce;
                    character1 = cha;
                }
            }
        }
        if(character1 != null){
            Tuple<String, List<Character>> result = new Tuple<>();
            List<Character> value = new ArrayList<>();
            value.add(character1);

            int add = (character1.getCurrentHp() + power) > character1.getHpMax() ? (character1.getHpMax()-character1.getCurrentHp()) : power;

            character1.hp().addAndGet(add);
            String builder = character.getName() + "施展" + getName()  + "(" + getLevel() + "级)" + "\t" +
                    character1.getName() + "增加生命力" + add + "----(" +
                    character1.getCurrentHp() + "/" + character1.getHpMax() + ")\n";
            result.setKey(builder);
            result.setValue(value);
            return result;
        }
        else{
            return simpleSkillLaunch(character,defences,null);
        }
    }

    @Override
    protected int computeHarm(Character character) {
        return (int) (character.getMagic() * ((100 + 50 + getLevel() * 1.2) / 100));
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }
}
